package com.lry.basic.algorithm.simple;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2020/1/6
 */
public class Sqrt {
    public static void main(String[] args) {
        System.out.println(mySqrt(200));
    }
    public static int mySqrt(int x) {
        if(x<=3)return x;

        int start = 2;
        int end = x/2;

        while(start<end){
            int mid = (start+end)>>1;

            if(x/mid>=mid&& x/(mid+1)<mid+1){
                return mid;
            }
             if(x/mid>mid){
                start = mid + 1;
            }else{
                end = mid - 1;
            }
        }

        return start;
    }
}
